package com.weixin.project.Util;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.annotations.JsonAdapter;
import org.omg.CORBA.PUBLIC_MEMBER;

public class ResponseUtil {
    public static JSONObject userNotFind(){
        return error("You are not login in or your login has expired");
    }

    public static JSONObject requireLogin() {
        return error("please login first!");
    }

    public static JSONObject requireVIP() {
        return error("You need to become VIP first");
    }

    public static JSONObject requireAdmin() {
        return error("This operation requires admin privileges");
    }

    public static JSONObject accessError() {
        return error("You don't have the permission to do this");
    }

    public static JSONObject error(String msg){
        return ResponseUtil.response(false, msg, new JSONObject());
    }

    public static JSONObject success(String msg, JSONObject obj){
        return response(true, msg, obj);
    }

    public static JSONObject success(JSONObject obj){
        return success("", obj);
    }

    public static JSONObject success(String msg){
        return success(msg, new JSONObject());
    }

    public static JSONObject success(){
        return success("");
    }

    private static JSONObject response(Boolean success, String msg, JSONObject body) {
        JSONObject ret = new JSONObject();
        ret.put("success", success);
        ret.put("msg", msg);
        ret.putAll(body);
        return ret;
    }
}
